<?php
//导入头文件
	include ('header.php');
	header('content-type:text/html;charset=utf8');
	//header('content-type:application/json;charset=utf8');
	
	//判断并打开session
	if(!isset($_SESSION)){
    session_start();
	}
	$agent = check_wap();
	if($agent){
	
	}else{
		
		include ('caidanlan.php');
}


	$cid = $_SESSION["cid"];
	
	
	//取值并判断
	if (isset($_GET["uname"]))
 	{
		$uname=$_GET["uname"];
	}
	else
	{
		$uname="";
	}
	if (isset($_GET["pass"]))
 	{
		$pass=$_GET["pass"];
	}
	else
	{
		$pass="";
	}
	if (isset($_GET["tel"]))
 	{
		$tel=$_GET["tel"];
		
	}
	else
	{
		$tel="";
	}
	if (isset($_GET["company"]))
 	{
		$company=$_GET["company"];
	}
	else
	{
		$company="";
	}
	if (isset($_GET["bumen"]))
 	{
		$bumen=$_GET["bumen"];
	}
	else
	{
		$bumen="";
	}
	if (isset($_GET["yonghujibie"]))
 	{
		$yonghujibie=$_GET["yonghujibie"];
	}
	else
	{
		$yonghujibie="";
	}
	if($uname=="" || $uname==null and $pass=="" || $pass==null and $tel=="" || $tel==null and $company=="" || $company==null and $bumen=="" || $bumen==null and $yonghujibie=="" || $yonghujibie==null)
	{
		
	}
	else if($uname=="" || $uname==null)
	{
		
	}
	else if($pass=="" || $pass==null)
	{
		
	}
	else if($tel=="" || $tel==null)
	{
		
	}
	else if($company=="" || $company==null)
	{
		
	}
	else if($bumen=="" || $bumen==null)
	{
		
	}
	else if($yonghujibie=="" || $yonghujibie==null)
	{
		
	}
	else
	{
		//操作数据库
		$telsql="select movephoto from a00user where jihuo=\"1\" and movephoto=\"$tel\"";
		$telsql1=mysql_query($telsql);
		$telsql2=mysql_num_rows($telsql1);
		if($telsql2>0)
		{
			echo "<script>"."alert('该号码已被注册')"."</script>";
			redirect('adduser.php');
		}
		else
		{
			mysql_select_db("che2");
			mysql_query("set names 'utf8'");
			$sqlc1="select ugb from jibie where mingcheng=\"$yonghujibie\"";
			$sqlc2=mysql_query($sqlc1);
			$sqlc3=mysql_fetch_row($sqlc2);
			$ugb=$sqlc3[0];
			$addsqlaa1="insert into a00user(c_id,ugb,uname,pass,movephoto,jihuo,company,bumen) values(\"$cid\",\"$ugb\",\"$uname\",\"$pass\",\"$tel\",\"1\",\"$company\",\"$bumen\")";
    	//echo $addsqlaa1;
			mysql_query($addsqlaa1);
		
			$sqlb="select uname from a00user where uname = \"$uname\" and c_id = \"$cid\" and pass = \"$pass\"";
		//echo $sqlb;
			$sqlb1 = mysql_query($sqlb);

			$sqlb3=mysql_num_rows($sqlb1);

			if($sqlb3>0)
			{
			echo "<script>"."alert('新增成功')"."</script>";
			//redirect('adduser.php');
			}
			else
			{
			echo "<script>"."alert('新增失败')"."</script>";
			//redirect('adduser.php');
			}
		}
		
		
	}
	
//页面显示的主题内容,

echo <<<end
	
	 <div class="container">
      <form class="form-signin" method='get' action='adduser.php'>
        
		      <label> 用户名：</label> 
			   <input type="text" name='uname' placeholder="请输入姓名">
		      <label> 密&nbsp;&nbsp;码：</label>
			  <input type="password" name='pass' placeholder="请输入密码">
			  <label> 手机号码：</label>
			  <input type="text" name='tel' id='tel' placeholder="请输入手机号码" onblur="isnum(tel)">
end;

	$sqla1="select company from company where c_id=\"$cid\"";
	$sqla2=mysql_query($sqla1);
	$sqla3=mysql_fetch_row($sqla2);
echo <<<end1
		<label>公司：</label>
	<input type="text" value="$sqla3[0]" name="company" placeholder="请填写公司">
	
	 <label>  用户部门：</label> 
	 <select name="bumen" id="bumen">
	 
end1;
	 
	mysql_query("SET NAMES UTF8");
	mysql_query("set character_set_client=utf8"); 
	mysql_query("set character_set_results=utf8");
	//$bumensql="select distinct bumen from a00user where c_id=\"$cid\"";
	$bumensql="select distinct bumen from a00user where c_id=\"$cid\"";
	//echo 123123;
	//echo $bumensql;
	$bumensql1=mysql_query($bumensql);
	while ($bumensql2=mysql_fetch_row($bumensql1))
	 {
		foreach ($bumensql2 as $bumensql3)
		 {
			 if($bumensql3 ==null or $bumensql3 == "")
			 {
				 
			 }
			 else
			 {
				 echo "<option value='$bumensql3'>$bumensql3</option>";
			 }
			
		}
	} 
	echo "</select>";
	echo "<label> 用户级别：</label> ";
	echo "<select name='yonghujibie'>";

	
	$jibiesql="select mingcheng from jibie where mingcheng !='公司管理员' and mingcheng !='超级管理员' and mingcheng !='运营管理员'";
	$jibiesql1=mysql_query($jibiesql);
		
	while ($jibiesql2=mysql_fetch_row($jibiesql1))
	 {
		foreach ($jibiesql2 as $ff6)
		 {
			echo "<option value='$ff6'>$ff6</option>";
		}
	}
	
	echo <<<end2
	</select>
	</br>
		<button class="btn btn-primary" type="submit">新&nbsp;&nbsp;增</button> &nbsp;&nbsp;
		<a href="usermanage.php" class="btn btn-primary btn-lg" role="button">返&nbsp&nbsp回</a>
       </form>
 </div>

end2;

//js
echo <<<end3
	<script type="text/javascript">  
	function isnum(obj)
	{
	var reg=/^1[0-9]{10}/;     
	if(!reg.test(obj.value))
	{
	alert("请正确填写手机号!");     
    
	}    
	}
	</script> 



end3;


include 'bottom.php';
?>